package com.gdcp.travel.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gdcp.travel.bean.Product;
import com.gdcp.travel.service.ProductService;

@Controller
public class ProductController {

	@Autowired
	protected ProductService productService;
	
	@RequestMapping("/product/show")
	//向浏览器响应json数据，把product对象转换成json
	@ResponseBody
	public Product showProduct(long id) {
		Product product = productService.getProductById(id);
		return product;
	}
	@RequestMapping("/product/list")
	public String getProductList(Model model) {
		List<Product> productList = productService.getProductList();
		//把列表传递给jsp
		model.addAttribute("productList", productList);
		//返回逻辑视图
		return "product-list";
	}

}
